setwd("C:/Users/Daniel Segura/Documents/Tarea PROGRA")
dcl <- read.csv("./liberia_datos_climaticos.csv", na.strings = "")
head(dcl)
## Date Temperatura..Celsius. HumedadRelativa.... VelocidadViento..m.s.
## 1 1/1/2015 27,88 65,08 7,08
## 2 2/1/2015 28,06 66,21 6,47
## 3 3/1/2015 28,91 65,21 5,40
## 4 4/1/2015 28,13 67,88 6,61
## 5 5/1/2015 28,00 66,25 8,85
## 6 6/1/2015 27,68 68,00 7,40
## Lluvia..mm. Irradiacion..W.m2. EvapoTranspiracion..mm.
## 1 0,00 228,58 5,04
## 2 0,00 231,17 4,86
## 3 0,00 244,17 5,12
## 4 0,00 182,38 4,13
## 5 0,00 246,00 5,38
## 6 0,00 189,46 4,23
dim(dcl)
## [1] 1551 7
dcl <- na.omit(dcl)
dcl[!complete.cases(dcl),]
## [1] Date Temperatura..Celsius. HumedadRelativa....
## [4] VelocidadViento..m.s. Lluvia..mm. Irradiacion..W.m2.
## [7] EvapoTranspiracion..mm.
## <0 rows> (or 0-length row.names)
names(dcl) <- c(
"fecha",
"temperatura",
"huRelativa",
"velViento",
"lluvia",
"irradiacion",
"evaTranspi"
)
attach(dcl)
library(ggplot2)
library(dplyr)
library(plotly)
library(gridExtra)
library(gtable)
library(grid)
dcl$temperatura <- as.numeric(gsub(",",".", dcl$temperatura))
dcl$huRelativa <- as.numeric(gsub(",",".", dcl$huRelativa))
dcl$velViento <- as.numeric(gsub(",",".", dcl$velViento))
dcl$lluvia <- as.numeric(gsub(",",".", dcl$lluvia))
dcl$irradiacion <- as.numeric(gsub(",",".", dcl$irradiacion))
dcl$evaTranspi <- as.numeric(gsub(",",".", dcl$evaTranspi))
dcl <- dcl %>% mutate(fecha = as.Date(fecha, format = "%d/%m/%Y"))
a1 <- ggplot(dcl, aes(fecha, temperatura))+
geom_line(color="orange")+
geom_point()+
ggtitle("Temperatura")+
ylab("[°C]")+
theme(axis.text.x = element_blank(), axis.title.x.bottom = element_blank())
a2 <- ggplot(dcl, aes(fecha, huRelativa))+
geom_col(color="blue")+
ggtitle("Humedad relativa")+
ylab("[%]")+
theme(axis.text.x = element_blank(), axis.title.x.bottom = element_blank())
a3 <- ggplot(dcl, aes(fecha, velViento))+
geom_col(color="green")+
ggtitle("Velocidad Viento")+
ylab("[m/s]")+
theme(axis.text.x = element_blank(), axis.title.x.bottom = element_blank())
a4 <- ggplot(dcl, aes(fecha, lluvia))+
geom_col(color="orange")+
ggtitle("Lluvia")+
ylab("[mm]")+
theme(axis.text.x = element_blank(), axis.title.x.bottom = element_blank())
a5 <- ggplot(dcl, aes(fecha, irradiacion))+
geom_line(color="yellow")+
geom_point()+
ggtitle("Irradiacion")+
ylab("[W/m2]")+
theme(axis.text.x = element_blank(), axis.title.x.bottom = element_blank())
a6 <- ggplot(dcl, aes(fecha, evaTranspi))+
geom_col(color="blue")+
ggtitle("EvapoTranspiracion")+
ylab("[mm]")+
theme(
axis.text.x = element_text(angle = 90),
axis.title.x.bottom = element_blank()
)
grid.arrange(a1,a2,a3,a4,a5,a6, ncol=1, nrow=6)
Agrupamos los datos por fecha y mes, se ordenan ascendentemente
dcl_by_month <- dcl %>% group_by(month = format(fecha, "%Y-%m")) %>% arrange(month)
dcl_monthly <- dcl_by_month %>% summarise(temperatura = mean(temperatura))
dcl_monthly <- dcl_by_month %>% summarise(huRelativa = mean(huRelativa)) %>%
merge(dcl_monthly, by="month")
dcl_monthly <- dcl_by_month %>% summarise(velViento = mean(velViento)) %>%
merge(dcl_monthly, by="month")
dcl_monthly <- dcl_by_month %>% summarise(lluvia = mean(lluvia)) %>%
merge(dcl_monthly, by="month")
dcl_monthly <- dcl_by_month %>% summarise(irradiacion = mean(irradiacion)) %>%
merge(dcl_monthly, by="month")
dcl_monthly <- dcl_by_month %>% summarise(evaTranspi = mean(evaTranspi)) %>%
merge(dcl_monthly, by="month")
p1 <- ggplot(dcl_monthly, aes(x=month, y=temperatura, group=1)) +
geom_line(color = "yellow")+
geom_point()+
ggtitle("Promedios mensuales de temperatura de Liberia") +
ylab("[°C]") +
theme(axis.text.x = element_blank(), axis.title.x.bottom = element_blank())
p2 <- ggplot(dcl_monthly, aes(x=month, y=huRelativa)) +
geom_col(color = "blue")+
ggtitle("Promedios mensuales de humedad relativa de Liberia") +
xlab("Fecha") +
ylab("(%)") +
theme(axis.text.x = element_blank(), axis.title.x.bottom = element_blank())
p3 <- ggplot(dcl_monthly, aes(x=month, y=velViento)) +
geom_col(color = "green")+
ggtitle("Promedios mensuales de velocidad de viento en Liberia") +
xlab("Fecha") +
ylab("[m/s]") +
theme(axis.text.x = element_blank(), axis.title.x.bottom = element_blank())
p4 <- ggplot(dcl_monthly, aes(x=month, y=lluvia)) +
geom_col(color = "blue")+
ggtitle("Promedios mensuales de lluvia en Liberia") +
xlab("Fecha") +
ylab("[mm]") +
theme(axis.text.x = element_blank(), axis.title.x.bottom = element_blank())
p5 <- ggplot(dcl_monthly, aes(x=month, y=irradiacion, group=1)) +
geom_line(color = "orange") +
geom_point()+
ggtitle("Promedios mensuales de irradiacion de Liberia") +
ylab("[W/m2]") +
theme(axis.text.x = element_blank(), axis.title.x.bottom = element_blank())
p6 <- ggplot(dcl_monthly, aes(x=month, y=evaTranspi)) +
geom_col(color = "blue")+
ggtitle("Promedios mensuales de EvapoTranspiracion en Liberia") +
xlab("Fecha") +
ylab("[mm]") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=1, nrow=6)
dcl_by_month <- dcl %>%
group_by(month = format(fecha, "%Y-%m")) %>%
arrange(month)
dcl_by_month <- dcl_by_month %>%
summarise(irradiacion = sum(irradiacion), lluvia = sum(lluvia) )
plot_ly(
data = dcl_by_month,
x = ~ month, y = ~ irradiacion,
name = "Irradiavcion",
type = "scatter",
mode = "lines",
line = list(color = "yellow")
) %>% add_trace(
y = dcl_by_month$lluvia,
name = "Lluvia",
mode = "lines",
line = list(color = "blue")
) %>% layout(
title = "Acumulaciones mensuales de irradiacion y lluvia en Liberia",
yaxis = list(title = "mm"),
xaxis = list(title = "Fecha")
)
c1 <- ggplot(
dcl, aes(x = temperatura)
) + geom_point(
aes(y = lluvia),
colour = "orange"
) +
ggtitle("Temperatura - lluvia") +
xlab("Temperatura [°C]") +
ylab("Lluvia [mm]")
c2 <- ggplot(
dcl, aes(x = huRelativa)
) + geom_point(
aes(y = lluvia),
colour = "blue"
) +
ggtitle("Humedad Relativa - lluvia") +
xlab("Humedad Relativa [%]") +
ylab("Lluvia [mm]")
c3 <- ggplot(
dcl, aes(x = velViento)
) + geom_point(
aes(y = lluvia),
colour = "orange"
) +
ggtitle("Velocidad Viento - lluvia") +
xlab("Velocidad viento [m/s]") +
ylab("Lluvia [mm]")
c4 <- ggplot(
dcl, aes(x = irradiacion)
) + geom_point(
aes(y = lluvia),
colour = "yellow"
) +
ggtitle("Irradiacion - lluvia") +
xlab("Irradiacion [W/m2]") +
ylab("Lluvia [mm]")
c5 <- ggplot(
dcl, aes(x = evaTranspi)
) + geom_point(
aes(y = lluvia),
colour = "green"
) +
ggtitle("EvapoTranspiracion - lluvia", ) +
xlab("EvapoTranspiracion [mm]") +
ylab("Lluvia [mm]")
c6 <- ggplot(
dcl, aes(x = irradiacion)
) + geom_point(
aes(y = huRelativa),
colour = "purple"
) +
ggtitle("Irradiacion - Humedad") +
xlab("Irradiacion [W/m2]") +
ylab("Humedad [%]")
grid.arrange(
c1, c2, c3, c4,c5,c6, ncol = 3,
bottom=textGrob("Relaciones entre datos de Liberia")
)